home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v9n07.arc / HEAPBUG.PAS < prev    next >
Pascal/Delphi Source File  |  1990-03-16  |  661b  |  26 lines

  1.  
  2. program HeapBug;
  3. CONST AllocSize : Word = $8000;
  4. VAR
  5.   P         : ARRAY[0..1] OF Pointer;
  6.   flip      : byte;
  7.   PrevAlloc : Word;
  8. BEGIN
  9.   flip := 0;
  10.   REPEAT
  11.     PrevAlloc := AllocSize;
  12.     WHILE MaxAvail < AllocSize DO
  13.       AllocSize := AllocSize DIV 2;
  14.     GetMem(P[flip], AllocSize);
  15.     Write('Allocated ', AllocSize:6 ,' bytes ');
  16.     Write('to pointer #', flip);
  17.     WriteLn(' -- MaxAvail is ',MaxAvail:8);
  18.     flip := succ(flip) MOD 2;
  19.   UNTIL MaxAvail <= 16;
  20.   Write('Deallocating ', PrevAlloc ,' bytes ');
  21.   WriteLn('from pointer #', flip);
  22.   FreeMem(P[flip], PrevAlloc);
  23.   WriteLn('NO crash -- FreeMin = ',FreeMin);
  24. END.
  25.  
  26.